
using System;
using System.Text;

namespace LightScribe
{
	public class DiscPrinter : IDisposable
	{
		private IntPtr printer;
		private string productName, vendorName, displayName, printerPath;
		private int driveInnerRadius, driveOuterRadius;
		private DeviceCapabilities deviceCapabilities;
		internal DiscPrinter(IntPtr printer)
		{
			this.printer = printer;
		}
		
		public bool Validated
		{
			get
			{
				return Interop.DiscPrinter_Validate(printer) == Error.OK;
			}
		}
		
		public string ProductName
		{
			get
			{
				if (productName == null)
				{
					int size;
					Interop.DiscPrinter_GetPrinterProductNameSize(printer, out size);
					StringBuilder builder = new StringBuilder(size);
					Interop.DiscPrinter_GetPrinterProductName(printer, builder);
					productName = builder.ToString();
				}
				return productName;
			}
			
		}
		
		public string VendorName
		{
			get
			{
				if (vendorName == null)
				{
					int size;
					Interop.DiscPrinter_GetPrinterVendorNameSize(printer, out size);
					StringBuilder builder = new StringBuilder(size);
					Interop.DiscPrinter_GetPrinterVendorName(printer, builder);
					vendorName = builder.ToString();
				}
				return vendorName;
			}
		}
		
		public string DisplayName
		{
			get
			{
				if (displayName == null)
				{
					int size;
					Interop.DiscPrinter_GetPrinterDisplayNameSize(printer, out size);
					StringBuilder builder = new StringBuilder(size);
					Interop.DiscPrinter_GetPrinterDisplayName(printer, builder);
					displayName = builder.ToString();
				}
				return displayName;
			}
		}
		
		public string PrinterPath
		{
			get
			{
				if (printerPath == null)
				{
					int size;
					Interop.DiscPrinter_GetPrinterPathSize(printer, out size);
					StringBuilder builder = new StringBuilder(size);
					Interop.DiscPrinter_GetPrinterPath(printer, builder);
					printerPath = builder.ToString();
				}
				return printerPath;
			}
		}
		
		public DeviceCapabilities DeviceCapabilities
		{
			get
			{
				if (deviceCapabilities == default(DeviceCapabilities))
					Interop.DiscPrinter_GetPrinterCapabilities(printer, out deviceCapabilities);
				return deviceCapabilities;
			}
		}
		
		public int DriveInnerRadius
		{
			get
			{
				if (driveInnerRadius == 0)
					Interop.DiscPrinter_GetDriveInnerRadius(printer, out driveInnerRadius);
				return driveInnerRadius;
				
			}
		}
		
		public int DriveOuterRadius
		{
			get
			{
				if (driveOuterRadius == 0)
					Interop.DiscPrinter_GetDriveOuterRadius(printer, out driveOuterRadius);
				return driveOuterRadius;
				
			}
		}
		
		public MediaInformation CurrentMedia
		{
			get
			{
				MediaInformation mediaInformation;
				Interop.DiscPrinter_GetCurrentMedia(printer, MediaOptimizationLevel.Generic, out mediaInformation);
				return mediaInformation;
			}
		}
		
		public uint PrintResolution(PrintQuality quality, MediaOptimizationLevel level)
		{
			uint resolution;
			Interop.DiscPrinter_GetPrintResolution(printer, quality, level, out resolution);
			return resolution;
		}
		
		public int LabelRegionOuterRadius(LabelMode mode, MediaOptimizationLevel level)
		{
			int radius;
			Interop.DiscPrinter_GetLabelRegionOuterRadius(printer, mode, level, out radius);
			return radius;
		}
		
		public int LabelRegionInnerRadius(LabelMode mode, MediaOptimizationLevel level)
		{
			int radius;
			Interop.DiscPrinter_GetLabelRegionInnerRadius(printer, mode, level, out radius);
			return radius;
		}
		
		public void OpenDriveTray()
		{
			Interop.DiscPrinter_OpenDriveTray(printer);
		}
		
		public void CloseDriveTray()
		{
			Interop.DiscPrinter_CloseDriveTray(printer);
		}
		
		public void LockDriveTray()
		{
			Interop.DiscPrinter_LockDriveTray(printer);
		}
		
		public void UnlockDriveTray()
		{
			Interop.DiscPrinter_UnlockDriveTray(printer);
		}
		
		public PrinterLock AcquireExclusiveUse()
		{
			return new PrinterLock(printer);
		}

		public PrintSession NewPrintSession()
		{
			return new PrintSession(printer);
		}
		
		public void Dispose()
		{
			Interop.DiscPrinter_Destroy(ref printer);
		}
	}
}
